/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pe.edu.cibertec.managed;

import java.util.Locale;
import java.util.ResourceBundle;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

@ManagedBean(name = "login")
@SessionScoped
public class LoginBean {

    private String username;
    private String password;
    private boolean resultado = true; // cambiar a true para poder ingresar

    public String autenticar() {

        ResourceBundle rb = ResourceBundle.getBundle("pe.edu.cibertec.recursos.mensajes",
                FacesContext.getCurrentInstance().getViewRoot().getLocale());

        if (!resultado) {
            FacesMessage fm = new FacesMessage();
            fm.setSeverity(FacesMessage.SEVERITY_ERROR);
            fm.setDetail(rb.getString("login_validacion_detalle"));
            fm.setSummary(rb.getString("login_validacion_resumen"));

            FacesContext.getCurrentInstance().addMessage(null, fm);
            return null;
        } else {
            password = null;
            return "principal";
        }


    }

    // Metodos de acceso JavaBeans
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
